package com.ruoyi.costumeShop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.costumeShop.domain.CostumeSalesperson;
import com.ruoyi.costumeShop.service.ICostumeSalespersonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * salespersonController
 * 
 * @author ruoyi
 * @date 2022-03-22
 */
@RestController
@RequestMapping("/costumeShop/salesperson")
public class CostumeSalespersonController extends BaseController
{
    @Autowired
    private ICostumeSalespersonService costumeSalespersonService;

    /**
     * 查询salesperson列表
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:salesperson:list')")
    @GetMapping("/list")
    public TableDataInfo list(CostumeSalesperson costumeSalesperson)
    {
        startPage();
        List<CostumeSalesperson> list = costumeSalespersonService.selectCostumeSalespersonList(costumeSalesperson);
        return getDataTable(list);
    }

    /**
     * 导出salesperson列表
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:salesperson:export')")
    @Log(title = "salesperson", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CostumeSalesperson costumeSalesperson)
    {
        List<CostumeSalesperson> list = costumeSalespersonService.selectCostumeSalespersonList(costumeSalesperson);
        ExcelUtil<CostumeSalesperson> util = new ExcelUtil<CostumeSalesperson>(CostumeSalesperson.class);
        util.exportExcel(response, list, "salesperson数据");
    }

    /**
     * 获取salesperson详细信息
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:salesperson:query')")
    @GetMapping(value = "/{salespersonId}")
    public AjaxResult getInfo(@PathVariable("salespersonId") Long salespersonId)
    {
        return AjaxResult.success(costumeSalespersonService.selectCostumeSalespersonBySalespersonId(salespersonId));
    }

    /**
     * 新增salesperson
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:salesperson:add')")
    @Log(title = "salesperson", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CostumeSalesperson costumeSalesperson)
    {
        return toAjax(costumeSalespersonService.insertCostumeSalesperson(costumeSalesperson));
    }

    /**
     * 修改salesperson
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:salesperson:edit')")
    @Log(title = "salesperson", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CostumeSalesperson costumeSalesperson)
    {
        return toAjax(costumeSalespersonService.updateCostumeSalesperson(costumeSalesperson));
    }

    /**
     * 删除salesperson
     */
    @PreAuthorize("@ss.hasPermi('costumeShop:salesperson:remove')")
    @Log(title = "salesperson", businessType = BusinessType.DELETE)
	@DeleteMapping("/{salespersonIds}")
    public AjaxResult remove(@PathVariable Long[] salespersonIds)
    {
        return toAjax(costumeSalespersonService.deleteCostumeSalespersonBySalespersonIds(salespersonIds));
    }
}
